﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TGVR.DataHelper.BussinessObject.BookingSystem;
using MDF.Requesting;
using TGVR.DataHelper.BussinessLogic.BookingSystem;
using HtmlAgilityPack;
using System.Globalization;
using MDF.Cacher.Managements;
using MDF.Logger.Managements;
using TGVR.DataHelper.BussinessObject;
using System.Web;

namespace TGVR_Boot
{
    public class TigerBoot : IBoot
    {
        Requester m_request = new Requester();
        private string m_Code;
        private int m_Total;
        private DateTime m_dtHoldTime;

        #region Search Old
        /*
        public List<BK_Ticket> Search(string _strStationForm, string _strStationTo, DateTime _dtDateFrom, DateTime? _dtDateTo, int _iAdut, int _iChild, int _iBaby, bool _isInter, int _iUserID)
        {
            #region Variables
            List<BK_Ticket> lstResult = new List<BK_Ticket>();
            decimal dDollarTiger = decimal.Parse(SettingBUS.Current.GetSetting(_iUserID, "DollarTiger").Value);
            decimal dFeeTiger = decimal.Parse(SettingBUS.Current.GetSetting(_iUserID, "FeeTiger").Value);
            #endregion
  
            #region Search
            string strLinkSearch = "http://booking.tigerair.com/Search.aspx";
            string strDataSearch = "";

            strDataSearch += string.Format("__EVENTTARGET=");
            strDataSearch += string.Format("&__EVENTARGUMENT=");
            strDataSearch += string.Format("&__VIEWSTATE=%2FwEPDwUBMGRk7p3dDtvn3PMYYJ9u4RznKUiVx98%3D");
            strDataSearch += string.Format("&pageToken=");
            strDataSearch += string.Format("&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24RadioButtonMarketStructure=RoundTrip");
            strDataSearch += string.Format("&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24HiddenFieldExternalRateId=");
            strDataSearch += string.Format("&ControlGroupSearchView_AvailabilitySearchInputSearchVieworiginStation1={0}", _strStationForm);
            strDataSearch += string.Format("&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24TextBoxMarketOrigin1={0}", _strStationForm);
            strDataSearch += string.Format("&ControlGroupSearchView_AvailabilitySearchInputSearchViewdestinationStation1={0}", _strStationTo);
            strDataSearch += string.Format("&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24TextBoxMarketDestination1={0}", _strStationTo);
            strDataSearch += string.Format("&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24DropDownListMarketDay1={0}", _dtDateFrom.ToString("dd"));
            strDataSearch += string.Format("&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24DropDownListMarketMonth1={0}", _dtDateFrom.ToString("yyyy-MM"));
            strDataSearch += string.Format("&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24DropDownListMarketDateRange1=1%7C1");
            strDataSearch += string.Format("&date_picker={0}", _dtDateFrom.ToString("yyyy-MM-dd"));
            strDataSearch += string.Format("&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24HiddenFieldExternalRateId=");
            strDataSearch += string.Format("&ControlGroupSearchView_AvailabilitySearchInputSearchVieworiginStation2=");
            strDataSearch += string.Format("&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24TextBoxMarketOrigin2=");
            strDataSearch += string.Format("&ControlGroupSearchView_AvailabilitySearchInputSearchViewdestinationStation2=");
            strDataSearch += string.Format("&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24TextBoxMarketDestination2=");
            strDataSearch += string.Format("&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24DropDownListMarketDay2={0}", _dtDateTo.HasValue ? _dtDateTo.Value.ToString("dd") : "");
            strDataSearch += string.Format("&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24DropDownListMarketMonth2={0}", _dtDateTo.HasValue ? _dtDateTo.Value.ToString("yyyy-MM") : "");
            strDataSearch += string.Format("&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24DropDownListMarketDateRange2=1%7C1");
            strDataSearch += string.Format("&date_picker={0}", _dtDateTo.HasValue ? _dtDateTo.Value.ToString("yyyy-MM-dd") : "");
            strDataSearch += string.Format("&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24DropDownListPassengerType_ADT={0}", _iAdut);
            strDataSearch += string.Format("&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24DropDownListPassengerType_CHD={0}", _iChild);
            strDataSearch += string.Format("&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24DropDownListPassengerType_INFANT={0}", _iBaby);
            strDataSearch += string.Format("&hiddendAdultSelection={0}", _iAdut);
            strDataSearch += string.Format("&hiddendChildSelection={0}", _iChild);
            strDataSearch += string.Format("&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24HIDDENPROMOCODE=");
            strDataSearch += string.Format("&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24DropDownListMCCCurrency=default");
            strDataSearch += string.Format("&ControlGroupSearchView%24ButtonSubmit=get+flights");

            var resSearch = m_request.PostData(strLinkSearch, strDataSearch);
            string strHtmlSearch = m_request.GetHtmlFromResponse(resSearch);
            #endregion
 
            //string strHtmlSearch = System.IO.File.ReadAllText(@"C:\Users\Nho Nhong Nheo\Desktop\tiger_search_result.html");
            #region Get Tickets
            HtmlDocument docSearch = new HtmlDocument();
            docSearch.LoadHtml(strHtmlSearch);
            var tickets = docSearch.DocumentNode.SelectNodes("//*[@id=\"tableMarket1\"]/tr/td[2]");
            foreach (var item in tickets)
            {
                BK_Ticket ti = new BK_Ticket();
                ti.AirType = "tigerair";
                ti.Class = item.Attributes["class"].Value;
                //Time
                //flightdatetimevalue arrivaldatetimevalue 10/07/2014|07:05
                var radio = item.SelectSingleNode(".//input[@type=\"radio\"]");
                if (radio == null)
                    return lstResult;
                //class="price"
                var price = item.SelectSingleNode(".//*[@class=\"price\"]").InnerText;
                string strCurrency = price.Split(' ')[0];
                string strPrice = price.Split(' ')[1];
                ti.PriceBefore = dDollarTiger * decimal.Parse(strPrice);
                ti.Price = dFeeTiger + ti.PriceBefore;
                //value
                string value = radio.Attributes["value"].Value;
                ti.DataToBook = value;
                value = value.Substring(value.IndexOf('|') + 1).Replace(" ~~", "");
                string[] arrTemp = value.Split('~');
                // 0   1   2         3          4       5    
                //TR~2323~SGN~10/02/2014 08:55~SIN~10/02/2014 11:55
                ti.FlightNo = arrTemp[0] + arrTemp[1];
                ti.FromCity = arrTemp[2];
                ti.ToCity = arrTemp[4];

                ti.StartDate = DateTime.ParseExact(arrTemp[3], "MM/dd/yyyy HH:mm", CultureInfo.InvariantCulture);
                ti.EndDate = DateTime.ParseExact(arrTemp[5], "MM/dd/yyyy HH:mm", CultureInfo.InvariantCulture);
                ti.LastUpdate = DateTime.Now;
                ti.IsInter = true;
                ti.Image = "http://thegioivere.net/content/images/logo/" + ti.FlightNo.Substring(0, 2) + ".png";
                if (ti.FromCity == _strStationForm)
                {
                    ti.TypeWay = "Out";
                    ti.TypeID = 1;
                }
                else
                {
                    if (_dtDateTo.HasValue && ti.FromCity == _strStationTo)
                    {
                        ti.TypeWay = "In";
                        ti.TypeID = 2;
                    }
                }
                lstResult.Add(ti);
            }
            #endregion

            return lstResult;
        }
         * */
        #endregion

        public List<BK_Ticket> Search(string _strStationForm, string _strStationTo, DateTime _dtDateFrom, DateTime? _dtDateTo, int _iAdut, int _iChild, int _iBaby, bool _isInter, int _iUserID)
        {
            string strKeyword = "TigerBoot_Search_" + _strStationForm + "_" + _strStationTo + _dtDateFrom.ToString("_MM_dd_yyyy") +
                (_dtDateTo.HasValue ? _dtDateTo.Value.ToString("_MM_dd_yyyy") : "") + _iAdut.ToString() + _iChild.ToString() + _iBaby.ToString() + "_User" + _iUserID;
            //m_log.Info("Search: " + strKeyword);
            var cacheResult = CacheManager.GetInstance().Get(strKeyword);
            if (cacheResult != null)
            {
                //m_log.Info("Get from cache");
                return (List<BK_Ticket>)cacheResult;
            }

            List<BK_Ticket> lstResult = new List<BK_Ticket>();

            if (!this.Login())
            {
                return lstResult;
            }
            Requester rq = m_request;

            string strTemp = "";
            strTemp += string.Format("TripRadio1={0}", _dtDateTo.HasValue ? "RT" : "OW");
            strTemp += string.Format("&cboOrigin={0}", _strStationForm);
            strTemp += string.Format("&cboDestination={0}", _strStationTo);
            strTemp += string.Format("&txtDepartDate={0}", _dtDateFrom.ToString("dd-MM-yyyy"));
            if (_dtDateTo.HasValue)
                strTemp += string.Format("&txtReturnDate={0}", _dtDateTo.Value.ToString("dd-MM-yyyy"));
            strTemp += string.Format("&cboAdult={0}", _iAdut);
            strTemp += string.Format("&cboChild={0}", _iChild);
            strTemp += string.Format("&cboInfant={0}", _iBaby);
            strTemp += string.Format("&btnSearch=Search");

            var respone = rq.PostData("http://agent.tayhogroup.com/", strTemp);
            string htmlRespone = rq.GetHtmlFromResponse(respone);
            //string htmlRespone = System.IO.File.ReadAllText(@"C:\Users\Nho Nhong Nheo\Desktop\tiger1.html");
            lstResult = GetFromHTML(htmlRespone, _strStationForm, _strStationTo, _dtDateFrom,
                _dtDateTo, _isInter, _iAdut + _iChild, _iUserID);

            if (lstResult != null && lstResult.Count > 0)
            {
                CacheManager.GetInstance().Add(strKeyword, lstResult.ToList());
            }

            return lstResult;
        }

        private List<BK_Ticket> GetFromHTML(string htmlRespone, string _strStationForm, string _strStationTo, DateTime _dtDateFrom, DateTime? _dtDateTo, bool _isInter, int p, int _iUserID)
        {
            decimal dDollarTiger = decimal.Parse(SettingBUS.Current.GetSetting(_iUserID, "DollarTiger").Value);
            decimal dFeeTiger = decimal.Parse(SettingBUS.Current.GetSetting(_iUserID, "FeeTiger").Value);

            List<BK_Ticket> lstResult = new List<BK_Ticket>();

            HtmlAgilityPack.HtmlNode.ElementsFlags.Remove("form");
            HtmlAgilityPack.HtmlNode.ElementsFlags.Remove("option");
            HtmlDocument doc = new HtmlDocument();

            doc.LoadHtml(htmlRespone);
            //var tickets = docSearch.DocumentNode.SelectNodes("//*[@id=\"tableMarket1\"]/tr/td[2]");
            var landding = doc.DocumentNode.SelectNodes("//*[@id=\"pnlH\"]");
            //Check stations
            string land1 = landding[2].InnerText;
            if (land1.IndexOf(_strStationForm) >= land1.IndexOf(_strStationTo))
            {
                LogManager.GetInstance().Error("Tiger find wrong ways");
                return lstResult;
            }

            if (_dtDateTo.HasValue)
            {
                string land2 = landding[3].InnerText;
                if (land2.IndexOf(_strStationTo) >= land2.IndexOf(_strStationForm))
                {
                    LogManager.GetInstance().Error("Tiger find wrong ways");
                    return lstResult;
                }
            }
            //
            #region Get Depart Tickets
            var lstTickets = doc.DocumentNode.SelectNodes("//*[@id=\"myTable1\"]//tr");
            var lstTickets2 = doc.DocumentNode.SelectNodes("//*[@id=\"myTable2\"]//tr");
            lstTickets.RemoveAt(0);
            foreach (var item in lstTickets)
            {
                BK_Ticket t = new BK_Ticket();
                var lstNodes = item.SelectNodes(".//td");
                t.AirType = "tigerair";
                t.TypeWay = "Out";
                t.FromCity = _strStationForm;
                t.ToCity = _strStationTo;

                t.FlightNo = lstNodes[1].InnerText;

                string strDateTemp = lstNodes[2].InnerText.Split(',')[1].Trim();
                string strTimeTemp = lstNodes[3].InnerText.Trim();
                string strTimeTemp1 = lstNodes[4].InnerText.Trim();
                //(+ 1 day)	
                int strAddDay = 0;
                int index = strTimeTemp1.IndexOf("(+");
                if (index > -1)
                {
                    string strNum = strTimeTemp1.Substring(index + 3, 1);
                    if (!Int32.TryParse(strNum, out strAddDay))
                    {
                        LogManager.GetInstance().Error("[Tiger] Get day extra error!");
                        return lstResult;
                    }
                    strTimeTemp1 = strTimeTemp1.Substring(0, index).Trim();
                }
                //Thu, 09-Oct-14 07.05 AM
                t.StartDate = DateTime.ParseExact(strDateTemp + " " + strTimeTemp, "dd-MMM-yy hh.mm tt", CultureInfo.InvariantCulture);
                t.EndDate = DateTime.ParseExact(strDateTemp + " " + strTimeTemp1, "dd-MMM-yy hh.mm tt", CultureInfo.InvariantCulture);
                t.EndDate = t.EndDate.AddDays(strAddDay);
                t.LastUpdate = DateTime.Now;
                t.IsInter = true;
                t.Image = "http://thegioivere.net/content/images/logo/" + t.FlightNo.Substring(0, 2) + ".png";

                //class="price"
                var strPrice = lstNodes[6].InnerText.Trim();
                t.PriceBefore = dDollarTiger * decimal.Parse(strPrice);
                t.Price = dFeeTiger + t.PriceBefore;

                var radio = item.SelectSingleNode(".//input[@type=\"radio\"]");
                if (radio == null)
                    return lstResult;
                t.DataToBook = radio.Attributes["value"].Value;
                lstResult.Add(t);
            }
            #endregion

            #region Get Return Tickets
            if (_dtDateTo.HasValue)
            {
                lstTickets2.RemoveAt(0);
                foreach (var item in lstTickets2)
                {
                    BK_Ticket t = new BK_Ticket();
                    var lstNodes = item.SelectNodes(".//td");
                    t.AirType = "tigerair";
                    t.TypeWay = "In";
                    t.FromCity = _strStationTo;
                    t.ToCity = _strStationForm;

                    t.FlightNo = lstNodes[1].InnerText;

                    string strDateTemp = lstNodes[2].InnerText.Split(',')[1].Trim();
                    string strTimeTemp = lstNodes[3].InnerText.Trim();
                    string strTimeTemp1 = lstNodes[4].InnerText.Trim();
                    //(+ 1 day)	
                    int strAddDay = 0;
                    int index = strTimeTemp1.IndexOf("(+");
                    if (index > -1)
                    {
                        string strNum = strTimeTemp1.Substring(index + 3, 1);
                        if (!Int32.TryParse(strNum, out strAddDay))
                        {
                            LogManager.GetInstance().Error("[Tiger] Get day extra error!");
                            return lstResult;
                        }
                        strTimeTemp1 = strTimeTemp1.Substring(0, index).Trim();
                    }
                    //Thu, 09-Oct-14 07.05 AM
                    t.StartDate = DateTime.ParseExact(strDateTemp + " " + strTimeTemp, "dd-MMM-yy hh.mm tt", CultureInfo.InvariantCulture);
                    t.EndDate = DateTime.ParseExact(strDateTemp + " " + strTimeTemp1, "dd-MMM-yy hh.mm tt", CultureInfo.InvariantCulture);
                    t.EndDate = t.EndDate.AddDays(strAddDay);
                    t.LastUpdate = DateTime.Now;
                    t.IsInter = true;
                    t.Image = "http://thegioivere.net/content/images/logo/" + t.FlightNo.Substring(0, 2) + ".png";

                    //class="price"
                    var strPrice = lstNodes[6].InnerText.Trim();
                    t.PriceBefore = dDollarTiger * decimal.Parse(strPrice);
                    t.Price = dFeeTiger + t.PriceBefore;

                    var radio = item.SelectSingleNode(".//input[@type=\"radio\"]");
                    if (radio == null)
                        return lstResult;
                    t.DataToBook = radio.Attributes["value"].Value;
                    lstResult.Add(t);
                }
            }
            #endregion

            return lstResult;
        }

        private bool Login()
        {
            //return true;
            string strLink = "http://agent.tayhogroup.com/index.php/auth";
            string strData = "login_identity=tigercb%40hongngocha.com&login_password=Hongha02&login_user=Login";
            var res = m_request.PostData(strLink, strData);
            string strHTML = m_request.GetHtmlFromResponse(res);
            bool isLogined = strHTML.IndexOf("Logout") > -1;
            return isLogined;
        }

        public List<BK_Ticket> SearchCheapest(string _strStationForm, string _strStationTo, DateTime _dtDateFrom, DateTime? _dtDataTo, int _iAdut, int _iChild, int _iBaby, int _iUserID)
        {
            throw new NotImplementedException();
        }

        public int MakeBooking(BK_Booking booking, BK_Passenger[] passenges, BK_Ticket tkDepart, BK_Ticket tkReturn, int _iUserID)
        {
            #region Variables

            string strEmailDefault = "thegioviere@gmail.com";

            bool isBackReturnToDepart = false;
            if (tkDepart == null && tkReturn != null)//2 chieu # hang
            {
                isBackReturnToDepart = true;
                tkDepart = tkReturn;
                tkReturn = null;
            }

            #endregion

            #region 1.1 Login

            if (!Login())
            {
                LogManager.GetInstance().Error("Tiger: Not login");
                return (int)BookingStatus.NOTLOGIN;
            }

            #endregion

            #region 1.2 Search

            int iAdut = passenges.Count(m => m.TypeID == 1);
            int iChild = passenges.Count(m => m.TypeID == 2);
            int iBaby = passenges.Count(m => m.TypeID == 3);

            //Clear cache
            string strKeyword = "TigerBoot_Search_" + booking.FromCity + "_" + booking.ToCity + tkDepart.StartDate.ToString("_MM_dd_yyyy") +
    (tkReturn != null ? tkReturn.StartDate.ToString("_MM_dd_yyyy") : "") + iAdut.ToString() + iChild.ToString() + iBaby.ToString() + "_User" + _iUserID;
            CacheManager.GetInstance().Delete(strKeyword);

            //Check price
            List<BK_Ticket> lstTickets = null;
            if (tkReturn != null)
                lstTickets = this.Search(booking.FromCity, booking.ToCity, tkDepart.StartDate,
                tkReturn.StartDate, iAdut, iChild, iBaby, true, _iUserID);
            else
                lstTickets = this.Search(booking.FromCity, booking.ToCity, tkDepart.StartDate,
                null, iAdut, iChild, iBaby, true, _iUserID);

            if (lstTickets.Count(m => m.FlightNo == tkDepart.FlightNo && m.Price == tkDepart.Price) == 0)
            {
                LogManager.GetInstance().Error("Tiger-Booking: Change price");
                return (int)BookingStatus.CHANGEDPRICE;
            }

            if (tkReturn != null && lstTickets.Count(m => m.FlightNo == tkReturn.FlightNo && m.Price == tkReturn.Price) == 0)
            {
                LogManager.GetInstance().Error("Tiger-Booking: Change price");
                return (int)BookingStatus.CHANGEDPRICE;
            }

            #endregion

            #region 1.3 Select

            string strLinkSelect = "http://agent.tayhogroup.com/";
            string strDataSelect = "";

            strDataSelect += string.Format("rdoFlight1={0}", tkDepart.DataToBook);
            if (tkReturn != null)
                strDataSelect += string.Format("&rdoFlight2={0}", tkReturn.DataToBook);
            strDataSelect += string.Format("&btnSubmit=Next");
            strDataSelect += string.Format("&txtHiddenAdult={0}", iAdut);
            strDataSelect += string.Format("&txtHiddenChild={0}", iChild);
            strDataSelect += string.Format("&txtHiddenInfant={0}", iBaby);

            var resSelect = m_request.PostData(strLinkSelect, strDataSelect);
            string strHtmlSelect = m_request.GetHtmlFromResponse(resSelect);

            #endregion

            #region 1.4 Fill Passengers

            string strLinkPassenger = "http://agent.tayhogroup.com/index.php/PassengerForm";
            string strDataPassenger = "";

            for (int i = 0; i < passenges.Length; i++)
            {
                strDataPassenger += string.Format("&cboTitlePax{0}={1}", i, passenges[i].Sex == "M" ? "MR" : "MS");
                strDataPassenger += string.Format("&txtFirstNamePax{0}={1}", i, passenges[i].Name);
                strDataPassenger += string.Format("&txtLastNamePax{0}={1}", i, passenges[i].FirstName);
                strDataPassenger += string.Format("&CboDOBDayPax{0}={1}", passenges[i].Birthday.ToString("dd"));
                strDataPassenger += string.Format("&cboDOBMonthPax{0}={1}", passenges[i].Birthday.ToString("MM"));
                strDataPassenger += string.Format("&cboDOBYearPax{0}={1}", passenges[i].Birthday.ToString("yyyy"));
                strDataPassenger += string.Format("&cboNationalityPax{0}=VN", i);
                strDataPassenger += string.Format("&cboDocDayPax{0}={1}", i, passenges[i].PassportExp.ToString("dd"));
                strDataPassenger += string.Format("&cboDocMonthPax{0}={1}", i, passenges[i].PassportExp.ToString("MM"));
                strDataPassenger += string.Format("&cboDocYearPax{0}={1}", i, passenges[i].PassportExp.ToString("yyyy"));
                strDataPassenger += string.Format("&txtPassportNoPax{0}={1}", i, passenges[i].PassportNo);

                //Depart info
                strDataPassenger += string.Format("&cboSSRBAGGAGE{2}-{3}Pax{0}=AC{1}", i, isBackReturnToDepart ? passenges[i].BaggageReturnValue : passenges[i].BaggageDepartValue,
                    booking.FromCity, booking.ToCity);
                strDataPassenger += string.Format("&cboSSRMEAL{2}-{3}Pax{0}=", i,
                    booking.FromCity, booking.ToCity);
                strDataPassenger += string.Format("&chkSPEQ{2}-{3}Pax{0}_addon=Sports+Equipment%3AUSD+29.00", i,
                    booking.FromCity, booking.ToCity);
                strDataPassenger += string.Format("&chkBMF{2}-{3}Pax{0}_addon=Board+Me+First%3AUSD+5.00", i,
                    booking.FromCity, booking.ToCity);

                //Return info
                if (tkReturn != null)
                {
                    strDataPassenger += string.Format("&cboSSRBAGGAGE{2}-{3}Pax{0}=AC{1}", i, passenges[i].BaggageReturnValue,
                        booking.ToCity, booking.FromCity);
                    strDataPassenger += string.Format("&cboSSRMEAL{2}-{3}Pax{0}=", i,
                        booking.ToCity, booking.FromCity);
                    strDataPassenger += string.Format("&chkSPEQ{2}-{3}Pax{0}_addon=Sports+Equipment%3AUSD+29.00", i,
                        booking.ToCity, booking.FromCity);
                    strDataPassenger += string.Format("&chkBMF{2}-{3}Pax{0}_addon=Board+Me+First%3AUSD+5.00", i,
                        booking.ToCity, booking.FromCity);
                }
            }


            strDataPassenger += string.Format("&txtEmailAddress={0}", HttpUtility.UrlEncode(strEmailDefault));
            strDataPassenger += string.Format("&txtPhoneNo={0}", booking.Phone);
            strDataPassenger += string.Format("&chkTermAndConditon=on");
            strDataPassenger += string.Format("&btnNext=Next");

            var resPassenger = m_request.PostData(strLinkPassenger, strDataPassenger);
            string strHtmlPassenger = m_request.GetHtmlFromResponse(resPassenger);

            #endregion

            #region 1.5 Get Booking

            HtmlDocument docBooking = new HtmlDocument();
            docBooking.LoadHtml(strHtmlPassenger);

            //Get code
            m_Code = docBooking.DocumentNode.SelectSingleNode("//*[@id=\"wrap\"]/div/div[3]/div[1]/div/div/table/tbody/tr[1]/td[2]").InnerText;

            m_Code += string.Format("({0})", docBooking.DocumentNode.SelectSingleNode("//*[@id=\"wrap\"]/div/div[3]/div[1]/div/div/table/tbody/tr[1]/td[4]").InnerText);
            //Get toal payment
            string rTotal = docBooking.DocumentNode.SelectSingleNode("//*[@id=\"wrap\"]/div/div[3]/div[3]/div[2]/div[4]/div").InnerText;

            decimal dTotal = decimal.Parse(rTotal.Split(' ')[2]);

            decimal dDollarTiger = decimal.Parse(SettingBUS.Current.GetSetting(_iUserID, "DollarTiger").Value);

            m_Total = (int)(dDollarTiger * dTotal);

            //Get Hold time
            ////*[@id="wrap"]/div/div[3]/div[1]/div/div/table/tbody/tr[3]/td[4]
            string strTime = docBooking.DocumentNode.SelectSingleNode("//*[@id=\"wrap\"]/div/div[3]/div[1]/div/div/table/tbody/tr[3]/td[4]").InnerText;

            m_dtHoldTime = DateTime.ParseExact(strTime.Substring(0, strTime.LastIndexOf(' ')), "dd-MMM-yy hh.mm tt", CultureInfo.InvariantCulture);

            if (m_Code.Length == 6)
                return (int)BookingStatus.BOOKED;
            #endregion

            return (int)BookingStatus.UNKNOW;

        }

        public string GetCode()
        {
            return m_Code;
        }

        public int GetTotal()
        {
            return m_Total;
        }

        public DateTime GetHoldToDate()
        {
            return m_dtHoldTime;
        }


    }
}
